import { memo,ReactNode,FC } from "react";
import { Navigate, useLocation } from "react-router-dom";


// 权限组件
interface Iprops{
  children?:ReactNode
}

const Private:FC<Iprops>= memo((props)=>{
  const token = sessionStorage.getItem('token')
  const location = useLocation()

  if(token){
    return <>{props.children}</>
  }else{
    // 跳转到首页，添加redirect查询参数
    return <Navigate to={'/?redirect='+location.pathname}></Navigate>
  }
})

export default Private;